home *** CD-ROM | disk | FTP | other *** search
- Path: mothra.westworld.com!news
- From: art@osz.com (Art Schlefstein)
- Newsgroups: comp.lang.c++
- Subject: Template problem with Visual C++ 2.0
- Date: Fri, 05 Jan 1996 09:56:43 GMT
- Organization: Westworld Communications, Inc.
- Message-ID: <4cisvq$det@mothra.westworld.com>
- NNTP-Posting-Host: b8.westworld.com
- X-Newsreader: Forte Free Agent 1.0.82
-
-
- I'm writing a small class based on templates that Visual C++ 2.0
- chokes on. Here's a the .CPP file that I tried to compile:
-
- ------------------------------------------------------------------
-
- #include <stdio.h>
-
- template <class T, int n>
- class CVector
- {
- public:
- T data[n];
- };
-
- template <class T, int n>
- void test( CVector<T,n> &v ) /* line 13 */
- {
- printf("%f\n", (float) v.data[0]);
- }
-
- void main(void)
- {
- CVector<float,3> v1;
- v1.data[0] = 3.14159;
- test(v1);
- }
-
- ------------------------------------------------------------------
-
- When I compile this in Visual C++ 2., I get the following messages:
-
- Compiling...
- D:\users\CLAUDIO\vector\vector.cpp
- D:\users\CLAUDIO\vector\vector.cpp(13) : error C2975: 'CVector' :
- invalid template actual argument '#2', constant expression expected
- D:\users\CLAUDIO\vector\vector.cpp(16) : error C2997: 'test' :
- function parameter list must use template formal parameter 'n'
- D:\users\CLAUDIO\vector\vector.cpp(22) : fatal error C1903: unable to
- recover from previous error(s); stopping compilation
- Error executing cl.exe.
- vector.exe - 3 error(s), 2 warning(s)
-
- This code compiles fine with gcc 2.6.3. Any ideas? Is this a bug
- in Visual C++?
-
- Please e-mail responses because my news server has been acting up
- lately.
-
- Claudio Fahey
-
-